//
//  FUNTLCallApp.m
//  FuntlFramework
//
//  Created by liweimin on 13-11-13.
//  Copyright (c) 2013年 liweimin. All rights reserved.
//

#import "FUNTLCallApp.h"

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

@implementation FUNTLCallApp

//调用Google地图
+ (void)callGoogleMap:(double)startLon startLat:(double)startLat endLon:(double)endLon endLat:(double)endLat destination:(NSString *)destination; {
    NSString *urlString;
    if(SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        urlString = [NSString stringWithFormat:@"maps://?f=q&hl=en&geocode=&saddr=%f,%f&daddr=%f,%f", startLat, startLon, endLat, endLon];
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];
    }
    else {
        //6.0以后的调用方式
        CLLocationCoordinate2D to;
        to.latitude = endLat;
        to.longitude = endLon;
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:to addressDictionary:nil]];
        toLocation.name = destination;
        [MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil] launchOptions:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil] forKeys:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeKey, MKLaunchOptionsShowsTrafficKey, nil]]];
    }
}

//调用浏览器
+ (void)callBrowser:(NSString *)url {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}

@end
